package com.asdhawaii.otello.players;

import java.util.ArrayList;
import java.util.List;
import com.asdhawaii.otello.board.Move;
import com.asdhawaii.otello.board.Square;
import com.asdhawaii.otello.board.SquareContents;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
 * Tests the Level 2 AI.
 * 
 * @author Branden Ogata
 *
 */

public class TestLevel2Ai extends TestAbstractOtelloAi
{
  /**
   * Tests that the Level 2 AI behaves as expected.
   * 
   */
  
  @Test
  public void test()
  {
    Level2Ai ai = new Level2Ai(SquareContents.BLACK);
    Square[][] board = createEmptyBoard();
    List<Move> validMoves = new ArrayList<Move>();

    board[0][1].setContents(SquareContents.WHITE);
    board[0][2].setContents(SquareContents.BLACK);
    board[0][3].setContents(SquareContents.WHITE);
    board[0][5].setContents(SquareContents.WHITE);
    board[0][7].setContents(SquareContents.BLACK);    
    board[1][1].setContents(SquareContents.WHITE);
    board[2][5].setContents(SquareContents.WHITE);
    board[3][4].setContents(SquareContents.BLACK);
    board[4][6].setContents(SquareContents.BLACK);
    board[5][4].setContents(SquareContents.BLACK);
    board[5][6].setContents(SquareContents.WHITE);
    board[6][5].setContents(SquareContents.WHITE);
    
    // Test where corner move would be selected
    TestAbstractOtelloAi.createList(validMoves, new Move(0, 0), new Move(0, 4), new Move(1, 6), 
                                    new Move(2, 0), new Move(6, 6), new Move(7, 6));
    assertEquals("Test corner move", new Move(0, 0), ai.getMove(board, validMoves));
    
    // Test where contiguous X square would be selected
    board[0][0].setContents(SquareContents.BLACK);
    board[0][1].setContents(SquareContents.BLACK);
    validMoves.remove(new Move(0, 0));
    assertEquals("Test contiguous X square move", new Move(1, 6), ai.getMove(board, validMoves));
    
    // Test where A square move would be selected
    board[1][6].setContents(SquareContents.BLACK);
    board[2][5].setContents(SquareContents.BLACK);
    validMoves.remove(new Move(1, 6));    
    assertEquals("Test A square move", new Move(2, 0), ai.getMove(board, validMoves));
    
    // Test where other square move would be selected
    board[1][1].setContents(SquareContents.BLACK);
    board[2][0].setContents(SquareContents.BLACK);
    validMoves.remove(new Move(2, 0));
    assertEquals("Test other square move", new Move(0, 4), ai.getMove(board, validMoves));

    // Test where contiguous C square would be selected
    board[0][3].setContents(SquareContents.BLACK);
    board[0][4].setContents(SquareContents.BLACK);
    validMoves.remove(new Move(0, 4));
    validMoves.add(new Move(0, 6));
    assertEquals("Test contiguous C square move", new Move(0, 6), ai.getMove(board, validMoves));
    
    // Test where C square move would be selected
    board[0][5].setContents(SquareContents.BLACK);
    board[0][6].setContents(SquareContents.BLACK);
    validMoves.remove(new Move(0, 6));
    assertEquals("Test C square move", new Move(7, 6), ai.getMove(board, validMoves));

    // Test where X square move would be selected
    board[6][5].setContents(SquareContents.BLACK);
    board[7][6].setContents(SquareContents.BLACK);
    validMoves.remove(new Move(7, 6));
    assertEquals("Test X square move", new Move(6, 6), ai.getMove(board, validMoves));
  }

}
